package com.zhuozhou.jdyc.wight.dialog.adapter;

import android.content.Context;
import android.view.View;

import com.zhuozhou.jdyc.R;
import com.zhuozhou.jdyc.base.BaseRecyclerViewAdapter;
import com.zhuozhou.jdyc.base.BaseViewHolder;
import com.zhuozhou.jdyc.databinding.DialogCouponItemBinding;
import com.zhuozhou.jdyc.main.goods.bean.BasicsCommodityBase;

/**
 * Create by CherishTang on 2020/3/27 0027
 * describe:adapter
 */
public class CouponAdapter extends BaseRecyclerViewAdapter<BasicsCommodityBase.DataBean.DiscountBean, DialogCouponItemBinding> {
    public OnCouponItemClickListener mOnCouponItemClickListener;
    private String string;

    public CouponAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_coupon_item;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder baseViewHolder, int pos) {
        super.onBindViewHolder(baseViewHolder, pos);

    }

    @Override
    public void onBindHolder(BaseViewHolder<DialogCouponItemBinding> holder, int pos) {
        if (string != null) {
            holder.getBinding().tvReceive.setText(string);
        }
        holder.getBinding().setCoupon(mList.get(pos));
        holder.getBinding().tvReceive.setOnClickListener(v -> {
            if (mOnCouponItemClickListener != null) {
                mOnCouponItemClickListener.OnCouponItemClick(holder.getBinding().getRoot(), pos);
            }
        });
    }

    public void setText(String string) {
        this.string = string;
    }

    public void setOnCouponItemClickListener(OnCouponItemClickListener l) {
        mOnCouponItemClickListener = l;
    }

    public interface OnCouponItemClickListener {
        void OnCouponItemClick(View view, int position);
    }
}
